<?php


namespace app\admin\controller;

use app\common\lib\Auth;
use app\common\lib;
use think\Request;

class Data extends Base
{
    public function report_data()
    {
        $arr_year = $this->get_new_year();
        $comm_sql =  new lib\Commonsql();
        $college_data = $comm_sql->group_by_level('2',$arr_year['0']['name']);
        $this->assign([
            'new_year'     => $arr_year['0']['name'],
            'college_data' => $college_data
        ]);
        /*************************检测权限 开始***********************/
        $auth = new Auth();
        $request = Request::instance();
        if(!$auth->check($request->path(),$this->isLogin()->id)) {
            return $this->redirect('not_rule/index/index');
        }
        /*************************检测权限 结束***********************/
        return $this->fetch();
    }

    public function not_report_data()
    {
        $arr_year = $this->get_new_year();
        $comm_sql =  new lib\Commonsql();
        $college_data = $comm_sql->group_by_level('1',$arr_year['0']['name']);
        $this->assign([
            'new_year'     => $arr_year['0']['name'],
            'college_data' => $college_data
        ]);
        /*************************检测权限 开始***********************/
        $auth = new Auth();
        $request = Request::instance();
        if(!$auth->check($request->path(),$this->isLogin()->id)) {
            return $this->redirect('not_rule/index/index');
        }
        /*************************检测权限 结束***********************/
        return $this->fetch();
    }

    public function data_del()
    {
        if(\request()->isAjax()){
            $stu_year = \request()->param('stu_year');
            $_res = Model('Student')->where(['stu_year'=>$stu_year])->delete();
            if(!$_res) {
                return show('200','没有任何记录被删除',0);
            }
            return show('200',$_res.'条 记录被删除','1');
        }
        /*************************检测权限 开始***********************/
        $auth = new Auth();
        $request = Request::instance();
        if(!$auth->check($request->path(),$this->isLogin()->id)) {
            return $this->redirect('not_rule/index/index');
        }
        /*************************检测权限 结束***********************/
        $stu_year = Model('SchoolYear')->order(['name'=>'desc'])->select();
        $this->assign([
            'stu_year' => $stu_year
        ]);
        return $this->fetch();
    }
}